package com.sxj.corejava.code10_异常;

/**
 * @author 石小俊
 * 2024年07月26日 10:42
 */
public class Test07_debug调试 {

    public static void main(String[] args) {
        UserController userController = new UserController();
        userController.register();
    }

}

class UserDao {
    public void insertUser(String username, String password) {
        System.out.println("正在向数据库中插入数据");
    }
}

class UserService {
    private UserDao userDao = new UserDao();

    public void register(String username, String password) throws UserExistException {
        if ("admin".equals(username)) {
            throw new UserExistException("该用户名太受欢迎了,请更换一个");
        }
        double d = 0;
        for (int i = 0; i < 4; i++) {
            int j = 3 - i;
            //d = i / j;
        }
        userDao.insertUser(username, password);
        System.out.println("注册成功");
    }
}

class UserController {

    private UserService userService = new UserService();

    public void register() {
        // 从页面中获取用户输入的用户名与密码
        String username = "alice";
        String password = "123456";
        try {
            userService.register(username, password);
        } catch (UserExistException e) {
            System.err.println(e.getMessage());
        }
    }
}
